package com.example.smartcity_ikun3.ui.Smart.view

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import android.widget.RadioButton
import com.example.smartcity_ikun3.R
import com.example.smartcity_ikun3.logic.util.Util.show
import kotlinx.android.synthetic.main.activity_smart_more_one.*

class SmartMoreOne : AppCompatActivity() {

    val on1: String = "药物"
    val on3: String = "配专业资格医师"
    val on4: String = "提供轮椅"
    val on6: String = "护理"
    val on7: String = "精神药物治疗"



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        setContentView(R.layout.activity_smart_more_one)
        title = "健康评估"

        // 监听Radio
        setRadio()
    }

    /**
     * 监听
     */
    var more1: String? =  null
    var more2: String? =  null
    var more3: String? =  null
    private fun setRadio() {
        Radio1.setOnCheckedChangeListener { _, i ->
            val id = findViewById<RadioButton>(i)
            more1 = id.text.toString()
            setWhen(more1.toString(), more2.toString(), more3.toString())

            Radio2.setOnCheckedChangeListener { _, j ->
                val id1 = findViewById<RadioButton>(j)
                more2 = id1.text.toString()
                setWhen(more1.toString(), more2.toString(), more3.toString())

                Radio3.setOnCheckedChangeListener { _, k ->
                    val id2 = findViewById<RadioButton>(k)
                    more3 = id2.text.toString()
                    setWhen(more1.toString(), more2.toString(), more3.toString())
                }
            }
        }
    }

    private fun setWhen(str1: String?, str2: String?, str3:String?){
        val content = "$str1, $str2, $str3"
        One1.text = content

        if (str1 == "正常") {
            One1.text = "无需配置套餐"
        } else if (str1 == "痴呆") {
            One1.text = on1
        } else if (str1 == "抑郁") {
            One1.text = on3
        }else if (str1 == "暴力") {
            One1.text = on7
        }

        if (str2 == "正常"){
            One2.text = "无需配置套餐"
        }else if (str2 == "拄拐"){
            One2.text = on4
        }else if (str2 == "轮椅"){
            One2.text = on6
        }else if (str2 == "卧床"){
            One2.text = on6
        }


        if (str3 == "饮食"){
            One3.text = on6
        }else if (str3 == "洗澡"){
            One3.text = on6
        }else if (str3 == "穿衣"){
            One3.text = on6
        }else if (str3 == "修饰"){
            One3.text = on6
        }


        // 点击计算价格
        SmOk.setOnClickListener {
            if (str1.toString().isEmpty()){
                "你还没选择呢".show()
            }else{
                startActivity(Intent(this, SmartMoreOnePlusActivity::class.java).apply {
                    putExtra("one1", str1)
                    putExtra("one2", str2)
                    putExtra("one3", str3)
                })

            }

        }
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}